package com.lagou.client;

    /**
 * 编程实现客户端在初始化操作和关闭
     */
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * 自定义成员方法对象流和Socket
 */
public class ClientInitClose {
    private Socket s;
    private ObjectOutputStream oot;
    private ObjectInputStream ois;

    public ObjectOutputStream getOot() {
        return oot;
    }

    public void setOot(ObjectOutputStream oot) {
        this.oot = oot;
    }

    public ObjectInputStream getOis() {
        return ois;
    }

    public void setOis(ObjectInputStream ois) {
        this.ois = ois;
    }

    public void clientInit() throws IOException {
        //1、创建socket类型的对象并且指定通讯地址和端口号
        s = new Socket(InetAddress.getLocalHost(), 9999);
        //2、使用输入流和输出流通信
        oot = new ObjectOutputStream(s.getOutputStream());
        ois = new ObjectInputStream(s.getInputStream());
        System.out.println("连接服务器成功！");
    }

    /**
     * 自定义成员方法实现客户端的关闭
     * @throws IOException
     */
    public void clientClose() throws IOException {
        //3、关闭socket并且释放有关资源
        ois.close();
        oot.close();
        s.close();
        System.out.println("客户端成功关闭！");
    }



}



